// pages/addr/addr.js
const app = getApp()
const pathUrl = app.globalData.pathUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selectArray: [{
      "id": '10',
      "text": "思明区湖滨北路168号 8F"
    },
    {
      "id": '11',
      "text": "湖里区梧桐西路188号12栋2303室"
    },
    {
      "id": '12',
      "text": "湖里区五缘湾道1688号2203"
    }
    ],

    region: ['福建省', '厦门市', '湖里区'],
    customItem: '全部',
    isCheck: false, // 是否阅读并同意协议
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var that = this;
    var loginInfo = JSON.parse(wx.getStorageSync('loginInfo'))
    var telphone = wx.getStorageSync('telphone');
    var userId = wx.getStorageSync('userId');
    console.log(loginInfo)
    console.log(loginInfo.records[0].query13)
    var name = loginInfo.records[0].query13;
    that.setData({
      telphone: telphone,
      name: name,
      userId: userId
    })
    console.log(telphone)
    this.getList09();
  },
  getList09: function () {
    var that = this;
    wx.request({
      url: pathUrl + '/gzgl/fxyGzgl09/list',
      method: 'GET',
      data: {
        query13: that.data.telphone
      },
      success: function (res) {
        console.log(res.data.result.records[0])
        var list09 = res.data.result.records[0];
        var region = [list09.query18, list09.query20, list09.query22]
        that.setData({
          id:list09.id,
          orderno: list09.query07,
          contract:list09.query08,
          name: list09.query12,
          telphone: list09.query13,
          userid: list09.query14,
          lxr: list09.query15,
          lxdh: list09.query16,
          provinceCode:list09.query17,
          province: list09.query18,
          cityCode: list09.query19,
          city: list09.query20,
          areaCode: list09.query21,
          area: list09.query22,
          address: list09.query23,
          mail: list09.query24,
          region:region,
        })
      },
      fail: function (res) { }
    });
  },
  xieyi: function (e) {
    console.log(e.detail.value)
    if (e.detail.value == '') {
      this.setData({
        isCheck: false
      });
    } else {
      this.setData({
        isCheck: true
      });
    }
  },
  bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },
  name: function (e) {
    var that = this;
    var name = that.data.name;
    that.setData({
      name: e.detail.value
    })
  },
  province: function (e) {
    var that = this;
    var province = that.data.province;
    that.setData({
      province: e.detail.value
    })
  },
  city: function (e) {
    var that = this;
    var city = that.data.city;
    that.setData({
      city: e.detail.value
    })
  },
  area: function (e) {
    var that = this;
    var area = that.data.area;
    that.setData({
      area: e.detail.value
    })
  },
  address: function (e) {
    var that = this;
    var address = that.data.address;
    that.setData({
      address: e.detail.value
    })
  },
  handText: function (e) {
    var that = this;
    var handText = that.data.handText;
    that.setData({
      handText: e.detail.value
    })
  },
  mail: function (e) {
    var that = this;
    var mail = that.data.mail;
    that.setData({
      mail: e.detail.value
    })
  },
  //    userId 是 String(32) 用户 id
  //    contacts 是 String(32) 联系人
  //    mobile 是 String(20) 手机号
  //    provinceName    是 String(64) 省名称,如福建省
  //    cityName 是 String(64) 市名称,如厦门市
  //    districtName    是 String(64) 区名称,如思明区
  //    address 是 String(512) 详细地址
  //    email 是 String(256) 邮箱
  //    thirdAccount    否 String(32) 第三方账号
  // 确认签署
  btnConfirm: function () {
    var that = this;
    var mobile = that.data.telphone;
    var userId = that.data.userId;
    var contacts = that.data.name;
    var provinceName = that.data.region[0];
    // var provinceCode = that.data.userId;
    var cityName = that.data.region[1];
    // var cityCode = that.data.userId;
    var districtName = that.data.region[2];
    // var districtCode = that.data.userId;
    var address = that.data.address;
    var email = that.data.mail;
    var thirdAccount = that.data.thirdAccount;
    var data = {
      id: that.data.id,
      query07: that.data.orderno,
      query08: that.data.contract,
      query12: that.data.name,
      query13: that.data.telphone,
      query14: that.data.userid,
      query15: that.data.lxr,
      query16: that.data.lxdh,
      // query17: that.data.provinceCode,
      query18: that.data.region[0],
      // query19: that.data.cityCode,
      query20: that.data.region[1],
      // query21: that.data.areaCode,
      query22: that.data.region[2],
      query23: that.data.address,
      query24: that.data.mail,
      query39:'Y',
    }
    if (!that.data.isCheck) {
      wx.showToast({
        title: '请勾选确认事项',
        icon: 'none'
      })
      return false
    }
    wx.request({
      url: pathUrl + '/gzgl/fxyGzgl09/edit',
      method: 'PUT',
      data: data,
      // url: pathUrl + '/fxy/1/postDeliveryAddress',
      // method: 'POST',
      // data: data,
      success: function (res) {
        console.log(res)
        wx.showToast({
          title: '地址提交成功',
        })
        // var list09 = res.data.result.records[0];
        // that.setData({
        //   name: list09.query12,
        //   telphone: list09.query13,
        //   province: list09.query18,
        //   city: list09.query19,
        //   area: list09.query21,
        //   address: list09.query23,
        //   mail: list09.query24,
        // })
      },
      fail: function (res) { }
    });
    // wx.navigateTo({
    //   url: '../signdoc/signdoc'
    // });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})